#include<stdio.h>
#include<string.h>
int main()
{
	int n;
	scanf("%d",&n);
	while(n--)
{
	int x,y,z=0;
	scanf("%d %d",&x,&y);
	if(x>y)
	{
		int k=0;
		z=x^y;	
		
		printf("%d\n",z);
		return 0;
	}
	else if(x==y)
	{
		printf("%d\n",0);
		return 0;
	}
	else
	{
		int k1=0,k2=0;
		k1=y-x;
		z=x^y;
		printf("%d",z);
		k2=z;
		if((k2&k2-1)==0)
		printf("%d\n",k1<k2?k1:k2);
		else
		printf("%d\n",k1);
	}
}
	return 0;
}